package com.dxf.springcloud.controller;

import com.dxf.springcloud.entities.CommonPayment;
import com.dxf.springcloud.entities.Payment;
import com.dxf.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @PostMapping("/create")
    public CommonPayment create(@RequestBody Payment payment){
        int result = paymentService.create(payment);
        log.info("*****插入结果*****"+result);

        if (result>0){
            return  new CommonPayment(200,"插入数据成功",result);
        }else {
            return new CommonPayment(444,"掺入数据识别",null);
        }

    }

    @GetMapping("/getPaymentById/{id}")
    public CommonPayment getPaymentById(@PathVariable("id") Long id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("*****得到结果*****"+payment);

        if (payment!=null){
            return new CommonPayment(200,"查询成功",payment);
        }else {
            return new CommonPayment(555,"不存在");
        }


    }
}
